package screen;

import resources.IActivityRequestHandler;
import resources.Input;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import common.Constant;


public class LoadGameScreen extends Screen  {

	OrthographicCamera guiCam;
	private Loaddata thread;
	private boolean isPost = false;
	private boolean isLoad = false;
	
	public LoadGameScreen(Game game, IActivityRequestHandler requestHandler) {
		super(game,requestHandler);
//		requestHandler.showAds(true);
		guiCam = new OrthographicCamera(Constant.SCREEN_WIDTH,Constant.SCREEN_HEIGHT);
		guiCam.position.set(Constant.SCREEN_WIDTH/ 2, Constant.SCREEN_HEIGHT / 2, 0);
		loadResource();
		thread = new Loaddata();
	}
	
	public LoadGameScreen(Game game) {
		super(game);
//		requestHandler.showAds(true);
		guiCam = new OrthographicCamera(Constant.SCREEN_WIDTH,Constant.SCREEN_HEIGHT);
		guiCam.position.set(Constant.SCREEN_WIDTH/ 2, Constant.SCREEN_HEIGHT / 2, 0);
		loadResource();
		thread = new Loaddata();
	}
	
	@Override
	public void present() {
		
//		guiCam.update();
//		spriteBatch.setProjectionMatrix(guiCam.combined);
//		spriteBatch.begin();
//		spriteBatch.draw(bananaSlashRegion, 0, 0);
//		spriteBatch.end();
	}
	
	public void tick(Input input){
//		System.out.println("Hello2");
		if(!isPost) {
			thread.run();
			isPost = true;
		}
		if(isLoad){
			if(thread!= null && !thread.isAlive()){
				thread = null;
				System.gc();
//				System.out.println("alo");
				game.setScreen(new MainMenuScreen(game, requestHandler));
			} 
		}
	}

	@Override
	public void pause() {
		
	}

	@Override
	public void resume() {
		
	}
	private void loadResource() {
		
	}
	private void unloadResource(){

	}

	@Override
	public void dispose() {
		unloadResource();
        spriteBatch.dispose();
	}
	public void error (String fileName, Class type, Throwable t) {
        Gdx.app.error("AssetManagerTest", "couldn't load asset '" + fileName + "'", (Exception)t);
	}
	public class Loaddata extends Thread {
		public void run(){			
			isLoad = true;
		}
	}
}
